import { ResultCode } from './ResultCode';

/**
 * 分页响应结构体
 *
 * @author xulh
 * @since 2024/03/11
 */
interface Data<T> {
  list: T[];
  total: number;
}
export class PageResult<T> {
  code: string;
  data: Data<T>;
  msg: string;
  constructor(code: string, message: string, data: Data<T>) {
    this.code = code;
    this.msg = message;
    this.data = data;
  }

  static success(list: any[], total: number): PageResult<any> {
    return new PageResult<any>(
      ResultCode.SUCCESS.code,
      ResultCode.SUCCESS.msg,
      {
        list: list,
        total: total,
      },
    );
  }
}
